/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package boogie.assetgenerator.data;

import java.io.File;
import java.net.URI;
import org.apache.commons.io.FilenameUtils;

/**
 *
 * @author boogie
 */
public final class AssetsBuilder {

    private AssetsBuilder() {
    }
    private static final AssetsBuilder instance = new AssetsBuilder();

    public static AssetsBuilder getInstance() {
        return instance;
    }
    public URI relative = null;

    public AssetFolder build(File assetsFolder) {
        if (assetsFolder.listFiles() == null) {
            return new AssetFolder("Assets");
        }
        if (relative == null) {
            relative = assetsFolder.toURI();
        }
        String folderName = assetsFolder.getName();
        String replaceAll = folderName.replaceAll("-", "_");
        System.out.println(folderName);
        AssetFolder assets = new AssetFolder(replaceAll);

        for (File f : assetsFolder.listFiles()) {
            if (f.isDirectory()) {
                assets.addFolder(this.build(f));
            } else {
                String name = f.getName();
                String replaceAll1 = name.replaceAll("-", "_");
                System.out.println(replaceAll1);
                if(FilenameUtils.getExtension(replaceAll1).contains("data")){
                    continue;
                }
                Asset a = new Asset(FilenameUtils.removeExtension(replaceAll1), new File(this.relative).toURI().relativize(f.toURI()).getPath());
                assets.addAsset(a);
            }

        }

        return assets;
    }
}
